<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Siswa extends CI_Controller {

    function __construct() { //inisialisasi library dan helper yang perlu di load
        parent::__construct();
        $this->load->helper('form');
        $this->load->library('pagination');
        $this->load->library('parser');
        $this->load->model('all');
        $this->trueLogin();
    }

    function trueLogin() { //cek sudah login
        $log = $this->session->all_userdata();
        if (!isset($log) || $log['login'] != TRUE || $log['hak_akses'] != 3) {
            redirect('main');
        }
    }

    function index() {
        $this->trueLogin();
        redirect('siswa/home');
    }

    function home() {
        $this->trueLogin();
        $data['blog_title'] = 'Home';
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $id = $this->session->all_userdata();
        $data['user'] = $this->all->username($id);
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('siswa/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('the/home', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function profil() {
        $data['blog_title'] = 'Profil';
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $id = $this->session->all_userdata();
        if ($this->all->profil($id)) {
            $data['profil'] = $this->all->profil($id);
        } else {
            $data['profil'] = array();
        }
        $id = $this->session->all_userdata();
        $data['user'] = $this->all->username($id);
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('siswa/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('siswa/profil', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }
    
    function profil_update() {
        $this->trueLogin();
        $id = $this->session->all_userdata();
        $input = array(
            'email' => $this->input->post('email'),
            'phone' => $this->input->post('telepon'),
            'tmpt_lahir' => $this->input->post('tempat'),
            'tgl_lahir' => $this->input->post('tgl')
        );
        $this->all->profil_update($id, $input);
        redirect('siswa/profil');
    }
    
    function jadwal() {
        $this->trueLogin();
        $data['blog_title'] = 'Jadwal';
        if ($this->all->social()) {
            $data['social'] = $this->all->social();
        } else {
            $data['social'] = array();
        }
        $id = $this->session->all_userdata();
        if ($this->all->jadwal_mengajar($id)) {
            $data['jadwal'] = $this->all->jadwal_mengajar($id);
        } else {
            $data['jadwal'] = array();
        }
        $this->parser->parse('the/header', $data);
        $this->load->view('the/open_tag');
        $this->load->view('the/open_tag_sidebar_left');
        $this->load->view('siswa/menu');
        $this->load->view('the/close_tag_sidebar_left');
        $this->load->view('the/open_tag_news');
        $this->load->view('siswa/jadwal', $data);
        $this->load->view('the/close_tag_news');
        $this->load->view('the/close_tag');
        $this->load->view('the/footer');
    }

    function logout() {
        $this->session->sess_destroy();
        redirect();
    }

}

?>